from fabric.api import run, env


def restart():
    ip_list = ['127.0.0.1', '10.26.99.121']
    # ip_list = ["10.80.48.58"]
    env.use_ssh_config = True
    env.skip_bad_hosts = True
    bad_hosts_list = []
    success_host_list = []
    for i in ip_list:
        try:
            env.host_string = i
            print (i)
            print (run('killall gunicorn'))
            success_host_list.append(i)
        except Exception as e:
            print (e)
            bad_hosts_list.append(i)
    if bad_hosts_list:
        context = {"bad_hosts_list": bad_hosts_list,
                   "success_host_list": success_host_list}
    else:
        context = {"success_host_list": success_host_list, "success": "ok"}
    print (context)


if __name__ == '__main__':
    restart()
